import type { RouteRecordRaw } from "vue-router";

export const PageRouteEnum = {
    HOME: "/",
    LOGIN: "/auth/login",
    REGISTER: "/auth/register",
    FORGET_PASSWORD: "/auth/forget-password",
    USER_PROFILE: "/user/profile",
    USER_SETTINGS: "/user/settings",
    NOT_FOUND: "/error/404"
} as const;

export const AdminPageRouteEnum = {
    HOME: "/admin",
    LOGIN: "/admin/auth/login",
    REGISTER: "/admin/auth/register",
    FORGET_PASSWORD: "/admin/auth/forget-password",
    USER_PROFILE: "/admin/user/profile",
    USER_SETTINGS: "/admin/user/settings",
    NOT_FOUND: "/error/404"
} as const;

const constantRoutes: RouteRecordRaw[] = [
    // 域名重定向(不需要前台系统，管理系统独立使用时可开启)
    // {
    //     path: "/",
    //     redirect: "/admin/auth/login"
    // },
    // 基础布局路由
    {
        path: "/",
        component: () => import("@/layouts/BasicLayout.vue"),
        children: [
            { path: "", component: () => import("@/views/home/index.vue"), name: "home", meta: { title: "首页" } },
            {
                path: "category",
                component: () => import("@/views/category/index.vue"),
                name: "category",
                meta: { title: "栏目" }
            },
            {
                path: "/user",
                component: () => import("@/layouts/UserLayout.vue"),
                meta: { auth: true }, // 父 meta 会合并到子路由的 meta 中，但以子路由的 meta 优先
                children: [
                    // {
                    //     path: "page",
                    //     component: () => import("@/views/user/UserPage.vue"),
                    //     name: "page",
                    //     meta: { title: "个人主页" } // 用户个人主页，收藏、点赞、关注等
                    // },
                    {
                        path: "comments",
                        component: () => import("@/views/user/MyComment.vue"),
                        name: "comments",
                        meta: { title: "我的评论" }
                    },
                    {
                        path: "profile",
                        component: () => import("@/views/user/UserProfile.vue"),
                        name: "profile",
                        meta: { title: "个人信息" } // 用户个人详细信息修改
                    }
                ]
            },
            // 文章详情布局路由
            {
                path: "article",
                component: () => import("@/layouts/ArticleLayout.vue"),
                children: [
                    {
                        path: ":id",
                        component: () => import("@/views/article/ArticleDetail.vue"),
                        name: "article-detail",
                        meta: { title: "文章详情" }
                    }
                ]
            }
        ]
    },
    // 空白布局路由
    {
        path: "/auth",
        component: () => import("@/layouts/BlankLayout.vue"),
        children: [
            {
                path: "login",
                component: () => import("@/views/auth/LoginView.vue"),
                name: "login",
                meta: { title: "登录" }
            },
            {
                path: "register",
                component: () => import("@/views/auth/RegisterView.vue"),
                name: "register",
                meta: { title: "注册" }
            },
            {
                path: "forgot-password",
                component: () => import("@/views/auth/ForgotPassword.vue"),
                name: "forgot-password",
                meta: { title: "忘记密码" }
            }
        ]
    },
    // 集成后台管理系统，所有路由均在 /admin 路径下
    {
        path: "/admin",
        component: () => import("@/layouts/BlankLayout.vue"),
        children: [
            {
                path: "",
                component: () => import("@/layouts/admin-layout/index.vue"),
                meta: { title: "后台管理系统" },
                children: [
                    {
                        path: "",
                        redirect: { name: "admin_hotlist" }
                    },
                    {
                        path: "monitor",
                        component: () => import("@/views/admin/dashboard/monitor/index.vue"),
                        name: "monitor",
                        meta: { title: "监控台" }
                    },
                    {
                        path: "workbench",
                        component: () => import("@/views/admin/dashboard/workbench/index.vue"),
                        name: "workbench",
                        meta: { title: "工作台" }
                    },
                    {
                        path: "user",
                        component: () => import("@/views/admin/user/index.vue"),
                        name: "sysuser",
                        meta: { title: "系统用户管理" }
                    },
                    {
                        path: "hotlist",
                        component: () => import("@/views/admin/hotlist/index.vue"),
                        name: "admin_hotlist",
                        meta: { title: "热榜管理" }
                    },
                    {
                        path: "category",
                        component: () => import("@/views/admin/category/index.vue"),
                        name: "admin_category",
                        meta: { title: "分类管理" }
                    },
                    {
                        path: "article",
                        component: () => import("@/views/admin/article/index.vue"),
                        name: "admin_article",
                        meta: { title: "文章管理" }
                    },
                    {
                        path: "comment",
                        component: () => import("@/views/admin/comment/index.vue"),
                        name: "admin_comment",
                        meta: { title: "评论管理" }
                    }
                ]
            },
            {
                path: "auth",
                component: () => import("@/layouts/BlankLayout.vue"),
                children: [
                    {
                        path: "login",
                        component: () => import("@/views/admin/auth/LoginView.vue"),
                        name: "admin_login",
                        meta: { title: "管理员登录" }
                    },
                    {
                        path: "register",
                        component: () => import("@/views/admin/auth/RegisterView.vue"),
                        name: "admin_register",
                        meta: { title: "管理员注册" }
                    },
                    {
                        path: "forgot-password",
                        component: () => import("@/views/admin/auth/ForgotPassword.vue"),
                        name: "admin_forgot-password",
                        meta: { title: "忘记密码" }
                    }
                ]
            }
        ]
    }
];

const errorRoutes: RouteRecordRaw[] = [
    // 错误页面路由
    {
        path: "/error",
        component: () => import("@/layouts/BlankLayout.vue"),
        children: [
            {
                path: "403",
                component: () => import("@/views/error/403.vue"),
                name: "forbidden",
                meta: { title: "403" }
            },
            { path: "404", component: () => import("@/views/error/404.vue"), name: "not-found", meta: { title: "404" } }
            // { path: "500", component: () => import("@/views/error/500.vue") }
        ]
    },
    // 匹配任意路由
    {
        path: "/:pathMatch(.*)*",
        component: () => import("@/views/error/404.vue"),
        meta: { title: "404" }
    }
];

export const routes = [...constantRoutes, ...errorRoutes];
